package com.qiche.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qiche.model.VoucherPackage;
import com.qiche.service.VoucherPackageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * Created by Linzw on 2018/01/24.
 */
@Service("voucherPackageService")
public class VoucherPackageServiceImpl extends BaseService<VoucherPackage> implements VoucherPackageService {

    @Override
    public PageInfo<VoucherPackage> selectByPage(VoucherPackage pack, int page, int limit) {
        Example example = new Example(VoucherPackage.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(pack.getName())) {
            criteria.andLike("name", "%" + pack.getName() + "%");
        }
        if (pack.getAgentId()!=null) {
            criteria.andEqualTo("agentId", pack.getAgentId());
        }
        PageHelper.startPage(page, limit);
        List<VoucherPackage> packList = selectByExample(example);
        return new PageInfo<>(packList);
    }
}
